package de.karlNet.sambamanager.ldapController.commands;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Controller;

import de.karlNet.sambamanager.ldapController.ConfigurationTree;
import de.karlNet.sambamanager.ldapController.OriginalLdapTree;
import de.karlNet.sambamanager.ldapController.SchemaTree;
import de.karlNet.sambamanager.ldapModel.LdapDomainController;
import de.karlNet.sambamanager.ldapModel.LdapObject;

@Controller
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class FindFSMORoles extends LdapCommand {
	@Autowired
	private ConfigurationTree configurationTree;
	@Autowired
	private OriginalLdapTree originalLdapTree;
	@Autowired
	private SchemaTree schemaTree;

	public LdapDomainController findFSMORolesItSelf(
			LdapDomainController ldapDomainController) {
		ldapDomainController.getFsmoRoles().clear();
		LdapObject configurationEntry = this.configurationTree
				.findByServerRL(ldapDomainController.getDn());
		String dnNTDS = "CN=NTDS Settings,"
				+ configurationEntry.getDn();
		ldapDomainController.getFsmoRoles().addAll(
				this.configurationTree.getFSMORoles(dnNTDS));
		ldapDomainController.getFsmoRoles().addAll(schemaTree.getFSMORoles(dnNTDS));
		return ldapDomainController;
	}
}
